/*

* Copyright (C) 2023, KylinSoft Co., Ltd.

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 3, or (at your option)

* any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, see <http://www.gnu.org/licenses/&gt;.

*

*/



#include "stateslider.h"

//滑动条组件
StateSlider::StateSlider(QWidget *parent) : KSlider(parent)
{
    setOrientation(Qt::Orientation::Horizontal);
    setSliderType(KSliderType::SingleSelectSlider);
    setMaximum(2);
    setSingleStep(1);
    setPageStep(1);
    setFixedWidth(372);
}

StateSlider::~StateSlider() {}

void StateSlider::mousePressEvent(QMouseEvent *event)
{
    int currentX = event->pos().x();
    double per = currentX * 1.0 / this->width();
    int value = per * (this->maximum() - this->minimum()) + this->minimum();
    this->setValue(value);
    QSlider::mousePressEvent(event);
}

void StateSlider::setSliderValue()
{
#if 0
    int policy = -1;
    if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
        policy = m_PowerManagerGsettings->get(POWER_POLICY_AC).toInt();
    } else {
        policy = m_PowerManagerGsettings->get(POWER_POLICY_BATTERY).toInt();
    }
    switch (policy) {
        case Performance:
            this->setValue(2);
            break;
        case Balance:
            this->setValue(1);
            break;
        case EnergySaving:
            this->setValue(0);
            break;
        default:
            break;
    }
#endif
}
void StateSlider::sliderValueChanged(int value)
{
#if 0
    qDebug() << "slider value" << value << m_batteryState;
    if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
        switch (value) {
            case 0:
                m_PowerManagerGsettings->set(POWER_POLICY_AC, EnergySaving);
                break;
            case 1:
                m_PowerManagerGsettings->set(POWER_POLICY_AC, Balance);
                break;
            case 2:
                m_PowerManagerGsettings->set(POWER_POLICY_AC, Performance);
                break;
            default:
                break;
        }
    } else {
        switch (value) {
            case 0:
                m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, EnergySaving);
                break;
            case 1:
                m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Balance);
                break;
            case 2:
                m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Performance);
                break;
            default:
                break;
        }
    }
#endif
}
